package com.shiningstars.general;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

import android.annotation.SuppressLint;

import com.shiningstars.valuebeans.Feedback;

@SuppressLint("SimpleDateFormat")
public class FeedbackDateComparator implements Comparator<Feedback> {

	DateFormat df = new SimpleDateFormat("dd - MMM - yyyy");

	@Override
	public int compare(Feedback feedback1, Feedback feedback2) {
		try {
			if (null != feedback1.getQuestion3() && null != feedback2.getQuestion3()) {
				Date date1 = df.parse(feedback1.getQuestion3());
				Date date2 = df.parse(feedback2.getQuestion3());

				if (date1.equals(date2)) {
					return 0;
				} else if (date1.before(date2)) {
					return 1;
				} else if (date1.after(date2)) {
					return -1;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return 0;
	}
}